package com.twg.test;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.twg.controller.UserController;
import com.twg.model.Article;
import com.twg.model.User;
import com.twg.service.ArticleService;
import com.twg.service.UserService;
import com.twg.util.BaseLogger;
import com.twg.util.PageUtil;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class test {
	@Resource(type=com.twg.service.Impl.UserServiceImpl.class)
	private UserService userService;
	@Resource(type=com.twg.service.Impl.ArticleServiceImpl.class)
	private ArticleService articleService;
	@Test
	public void test(){
		List<User> userList = userService.selectUsers();
		for (User user : userList) {
			System.out.println(user);
			BaseLogger.writeLog(BaseLogger.logger, BaseLogger.INFO, user);
		}
		User user = new User();
		//user.setId(1);
		user.setUserAddress("台");
		//user.setUserName("桃");
		//user.setUserAge(23);
		int count = userService.countFromUser(user);
		System.out.println(count);
		System.out.println(user);
		PageUtil page = new PageUtil(1, 3, count);
		page.setUser(user);
		List<User> list = userService.pageFromUser(page);
		for (User user2 : list) {
			System.out.println(user2);
		}
		//System.out.println(userService.selectUserByID(10));
	}
	@Test
	public void testArticle(){
		List<Article> list = new ArrayList<Article>();
		//int count = articleService.selectArticleCountByUser(1);
		//int count = articleService.selectArticleCount();
		//PageUtil page = new PageUtil(1, 3, count);
		//page.setId(1);
		//list = articleService.pageArticleByUser(page);
		Article article = new Article();
		User user = new User();
		//user.setUserName("周");
		//article.setId(16);
		//article.setTitle("");
		article.setContent("我");
		//article.setUser(user);
		System.out.println(article);
		int count = articleService.selectFilterCount(article);
		PageUtil page = new PageUtil(1, 3, count);
		page.setArticle(article);
		list = articleService.pageFilterArticle(page);
		System.out.println(count);
		for (Article art : list) {
			System.out.println(art);
		}
	}

}
